package com.mantou.proxyservice.proxeservice.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.mantou.proxyservice.proxeservice.entity.Testurl;
import com.mantou.proxyservice.proxeservice.service.TesturlService;
import com.mantou.proxyservice.utils.ReturnCode;
import com.mantou.proxyservice.utils.ReturnContainer;

@Controller
@RequestMapping("/proxyservice")
public class TesturlRestApiController {

	private final Logger logger = LoggerFactory.getLogger(TesturlRestApiController.class);
	
	
	@Autowired
	private TesturlService testurlService;
	
	@RequestMapping(value = "/proxeservice/testurl/{id}", method = RequestMethod.GET)
	public ResponseEntity<ReturnContainer<Testurl>> getTesturlById(@PathVariable Integer id){
		Testurl testurl = testurlService.findByPrimaryKey(id);
		ReturnContainer<Testurl> responseEnv = new ReturnContainer<Testurl>(ReturnCode.OK.getStatus(),testurl);
		return new ResponseEntity<ReturnContainer<Testurl>>(responseEnv, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/proxeservice/testurl", method = RequestMethod.POST)
	public ResponseEntity<ReturnContainer<Integer>> createTesturl(@RequestBody Testurl testurl){
		Integer  result = testurlService.create(testurl);
		ReturnContainer<Integer> responseEnv = new ReturnContainer<Integer>(ReturnCode.OK.getStatus(),result);
		return new ResponseEntity<ReturnContainer<Integer>>(responseEnv, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/proxeservice/testurl/{id}", method = RequestMethod.DELETE)
	public ResponseEntity<ReturnContainer<Integer>> deleteTesturlByPrimaryKey(@PathVariable Integer id){
		Integer  result = testurlService.deleteByPrimaryKey(id);
		ReturnContainer<Integer> responseEnv = new ReturnContainer<Integer>(ReturnCode.OK.getStatus(),result);
		return new ResponseEntity<ReturnContainer<Integer>>(responseEnv, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/proxeservice/testurl/{id}", method = RequestMethod.PUT)
	public ResponseEntity<ReturnContainer<Integer>> updateTesturlByPrimaryKeySelective(@PathVariable Integer id, @RequestBody Testurl testurl){
		testurl.setId(id);
		Integer  result = testurlService.updateByPrimaryKeySelective(testurl);
		ReturnContainer<Integer> responseEnv = new ReturnContainer<Integer>(ReturnCode.OK.getStatus(),result);
		return new ResponseEntity<ReturnContainer<Integer>>(responseEnv, HttpStatus.OK);
	}
	
}
